﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataModel
{
    public class TermSetList : List<TermSet>
    {

        /// <summary>
        /// Adds the specified new term set.
        /// </summary>
        /// <param name="nTermSet">The new term set.</param>
        new public void Add(TermSet nTermSet)
        {
            if (!Contains(nTermSet.Name))
            {
                base.Add(nTermSet);
            }
        }

        /// <summary>
        /// Determines whether this [contains] [the specified name].
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public bool Contains(String name)
        {
            foreach (TermSet ts in this)
            {
                if (ts.Name == name)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// Gets the term set by name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public TermSet GetTermSetByName(String name)
        {
            foreach (TermSet ts in this)
            {
                if (ts.Name == name)
                {
                    return ts;
                }
            }
            return null;
        }

        /// <summary>
        /// Gets the term by unique identifier.
        /// </summary>
        /// <param name="guid">The unique identifier.</param>
        /// <returns></returns>
        public Term GetTermByGUID(String guid)
        {
            foreach(TermSet ts in this)
            {
                Term t = ts.getTermById(guid);
                if (t != null) { return t; }
            }

            return null;
        }

        /// <summary>
        /// Totals the term count.
        /// </summary>
        /// <returns></returns>
        public int totalTermCount()
        {
            int i = 0;
            foreach (TermSet ts in this)
            {
                i += ts.termCount();
            }
            return i;
        }
    }
}
